package org.cbg.panel;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JPanel;

import org.cbg.entity.Salegoods;
import org.come.until.CutButtonImage;

import com.tool.tcpimg.UIUtils;



public class TraslationWantBuyShouyeModelJpanel extends JPanel {

    /**
     * 最新上架信息图片
     */
    private JLabel[] tupianList;
    /**
     * 最新上架名称
     */
    private JLabel[] mingziList;

    /**
     * 最新上架价格
     */
    private JLabel[] jiageList;

    public TraslationWantBuyShouyeModelJpanel(int geshu) {

        this.setLayout(null);
        this.setBounds(0, 208, 740, 200);
        this.setOpaque(false);
        // 最新上架物品信息
        tupianList = new JLabel[7];
        mingziList = new JLabel[7];
        jiageList = new JLabel[7];
        for (int i = 0; i < tupianList.length; i++) {
            tupianList[i] = new JLabel();
            tupianList[i].setBounds(85 + (68+20) * i, 104, 58, 58);
            tupianList[i].setOpaque(false);

            mingziList[i] = new JLabel();
            mingziList[i].setOpaque(false);
            mingziList[i].setForeground(UIUtils.COLOR_cbg3);
            mingziList[i].setFont(UIUtils.TEXT_FONT78);
            mingziList[i].setBounds(85 + (68+20) * i, 168, 75, 15);

            jiageList[i] = new JLabel();
            jiageList[i].setOpaque(false);
            jiageList[i].setForeground(UIUtils.COLOR_cbg5);
            jiageList[i].setFont(UIUtils.TEXT_FONT2);
            jiageList[i].setBounds(85 + (68+20) * i, 101, 75, 15);
            this.add(jiageList[i]);
            this.add(tupianList[i]);
            this.add(mingziList[i]);
        }
    }

    public void setZuixinshangjia(JPanel jPanel, int geshu) {
        this.removeAll();
        this.repaint();
        for (int i = 0; i < geshu; i++) {
            /**
             * 最新上架图片设计
             */
            JLabel tupian = new JLabel();
            tupian.setBackground(Color.red);
            tupian.setOpaque(false);
            tupian.setIcon(CutButtonImage.getImage("inkImg/hongmu/2/202.png", 52, 50));
            tupian.setBounds(30 + 75 * i, 0, 52, 50);
            this.add(tupian);

            /**
             * 最新上架名称设计
             */
            JLabel mingzi = new JLabel("名字" + i);
            mingzi.setOpaque(false);
            mingzi.setForeground(Color.black);
            mingzi.setFont(new Font("宋体", Font.PLAIN, 14));
            mingzi.setBounds(30 + 75 * i, 55, 52, 15);
            this.add(mingzi);
            /**
             * 最新上架价格
             */
            JLabel jiage = new JLabel("价格" + i);
            jiage.setOpaque(false);
            jiage.setForeground(Color.black);
            jiage.setFont(new Font("宋体", Font.PLAIN, 14));
            jiage.setBounds(30 + 75 * i, 72, 52, 15);
            this.add(jiage);

            tupian.addMouseListener(new MouseListener() {

                @Override
                public void mouseReleased(MouseEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void mousePressed(MouseEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void mouseExited(MouseEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    // TODO Auto-generated method stub

                }

                @Override
                public void mouseClicked(MouseEvent e) {
                    // TODO Auto-generated method stub

                }
            });
        }
    }

    public void setZuixinshangjia(List<Salegoods> saleGoodsList) {
        for (int i = 0; i < 7; i++) {
            if (saleGoodsList.size() > i) {
                /**
                 * 最新上架图片设计
                 */
                if (saleGoodsList.get(i).getSaletype() == 4) {
                    tupianList[i].setIcon(CutButtonImage.getImage("img/newHead/p" + saleGoodsList.get(i).getSaleskin() + ".png", 58, 58));
//                    tupianList[i].setIcon(CutButtonImage.getImage(saleGoodsList.get(i).getSaleskin(), 58, 58));

                } else if (saleGoodsList.get(i).getSaletype() == 6) {
                    tupianList[i].setIcon(CutButtonImage.getImage(
                            "inkImg/old/lingbao/" + saleGoodsList.get(i).getSaleskin() + ".png", 58, 58));
                } else {
                    tupianList[i].setIcon(CutButtonImage.getImage(
                            "img/item/" + saleGoodsList.get(i).getSaleskin() + ".png", 58, 58));
                }
                /**
                 * 最新上架名称设计
                 */
                mingziList[i].setText(saleGoodsList.get(i).getSalename());
                /**
                 * 最新上架价格
                 */
                jiageList[i].setText(saleGoodsList.get(i).getSaleprice() + "");
            } else {
                tupianList[i].setIcon(null);
                jiageList[i].setText("");
                mingziList[i].setText("");
            }
        }
    }
}
